/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.charproperty.支持补集;

import java.util.HashMap;
import 解析.ASCII;
import 解析.node.charproperty.CharProperty;

/**
 *
 * @author yanxi
 */
public class CharPropertyNames {

    public static CharProperty支持补集 charPropertyFor(String name) {
        CharPropertyFactory m = map.get(name);
        return m == null ? null : m.make();
    } 
    /*
    private static abstract class CharPropertyFactory {

        abstract CharProperty make();
    }
    */
    private static void defCategory(String name, final int typeMask) { 
        map.put(name, new CharPropertyFactory() {
            @Override
            CharProperty支持补集 make() {
                charPropertyClassName=Category.class.getName();
                return new Category(typeMask);
            }
        }); 
        mapCategory.put(typeMask, name);
    }

    private static void defRange预定义POSIX字符类(String name, final int lower, final int upper) { 
        map.put(name, new CharPropertyFactory() {
            CharProperty支持补集 make() {
                //charPropertyClassName=Range.class.getName();
                //return Pattern.rangeFor(lower, upper);
                charPropertyClassName=Range预定义POSIX字符类.class.getName();
                return new Range预定义POSIX字符类(lower, upper);
            }
        }); 
        mapRange.put(""+lower+""+upper, name);
    }

    private static void defCtype(String name, final int ctype) {
        map.put(name, new CharPropertyFactory() {
            CharProperty支持补集 make() {
                charPropertyClassName=Ctype.class.getName();
                return new Ctype(ctype);
            }
        });
        mapCtype.put(ctype, name);
    }

    /*
    private static abstract class CloneableProperty extends CharProperty implements Cloneable {

        public CloneableProperty clone() {
            try {
                return (CloneableProperty) super.clone();
            } catch (CloneNotSupportedException e) {
                throw new AssertionError(e);
            }
        }
    }
    */
    private static void defClone(String name, final CloneableProperty p) {
        map.put(name, new CharPropertyFactory() {
            CharProperty支持补集 make() {
                return p.clone();
            }
        });
    }

    private static final HashMap<String, CharPropertyFactory> map = new HashMap<>();
    public static final HashMap<Integer,String> mapCategory=new HashMap<>();
    public static final HashMap<Integer,String> mapClone=new HashMap<>();
    public static final HashMap<Integer,String> mapCtype=new HashMap<>();
    public static final HashMap<String,String> mapRange=new HashMap<>();

    static {
        // Unicode character property aliases, defined in
        // http://www.unicode.org/Public/UNIDATA/PropertyValueAliases.txt
        defCategory("Cn", 1 << Character.UNASSIGNED);
        defCategory("Lu", 1 << Character.UPPERCASE_LETTER);
        defCategory("Ll", 1 << Character.LOWERCASE_LETTER);
        defCategory("Lt", 1 << Character.TITLECASE_LETTER);
        defCategory("Lm", 1 << Character.MODIFIER_LETTER);
        defCategory("Lo", 1 << Character.OTHER_LETTER);
        defCategory("Mn", 1 << Character.NON_SPACING_MARK);
        defCategory("Me", 1 << Character.ENCLOSING_MARK);
        defCategory("Mc", 1 << Character.COMBINING_SPACING_MARK);
        defCategory("Nd", 1 << Character.DECIMAL_DIGIT_NUMBER);
        defCategory("Nl", 1 << Character.LETTER_NUMBER);
        defCategory("No", 1 << Character.OTHER_NUMBER);
        defCategory("Zs", 1 << Character.SPACE_SEPARATOR);
        defCategory("Zl", 1 << Character.LINE_SEPARATOR);
        defCategory("Zp", 1 << Character.PARAGRAPH_SEPARATOR);
        defCategory("Cc", 1 << Character.CONTROL);
        defCategory("Cf", 1 << Character.FORMAT);
        defCategory("Co", 1 << Character.PRIVATE_USE);
        defCategory("Cs", 1 << Character.SURROGATE);
        defCategory("Pd", 1 << Character.DASH_PUNCTUATION);
        defCategory("Ps", 1 << Character.START_PUNCTUATION);
        defCategory("Pe", 1 << Character.END_PUNCTUATION);
        defCategory("Pc", 1 << Character.CONNECTOR_PUNCTUATION);
        defCategory("Po", 1 << Character.OTHER_PUNCTUATION);
        defCategory("Sm", 1 << Character.MATH_SYMBOL);
        defCategory("Sc", 1 << Character.CURRENCY_SYMBOL);
        defCategory("Sk", 1 << Character.MODIFIER_SYMBOL);
        defCategory("So", 1 << Character.OTHER_SYMBOL);
        defCategory("Pi", 1 << Character.INITIAL_QUOTE_PUNCTUATION);
        defCategory("Pf", 1 << Character.FINAL_QUOTE_PUNCTUATION);
        defCategory("L", ((1 << Character.UPPERCASE_LETTER)
                | (1 << Character.LOWERCASE_LETTER)
                | (1 << Character.TITLECASE_LETTER)
                | (1 << Character.MODIFIER_LETTER)
                | (1 << Character.OTHER_LETTER)));
        defCategory("M", ((1 << Character.NON_SPACING_MARK)
                | (1 << Character.ENCLOSING_MARK)
                | (1 << Character.COMBINING_SPACING_MARK)));
        defCategory("N", ((1 << Character.DECIMAL_DIGIT_NUMBER)
                | (1 << Character.LETTER_NUMBER)
                | (1 << Character.OTHER_NUMBER)));
        defCategory("Z", ((1 << Character.SPACE_SEPARATOR)
                | (1 << Character.LINE_SEPARATOR)
                | (1 << Character.PARAGRAPH_SEPARATOR)));
        defCategory("C", ((1 << Character.CONTROL)
                | (1 << Character.FORMAT)
                | (1 << Character.PRIVATE_USE)
                | (1 << Character.SURROGATE))); // Other
        defCategory("P", ((1 << Character.DASH_PUNCTUATION)
                | (1 << Character.START_PUNCTUATION)
                | (1 << Character.END_PUNCTUATION)
                | (1 << Character.CONNECTOR_PUNCTUATION)
                | (1 << Character.OTHER_PUNCTUATION)
                | (1 << Character.INITIAL_QUOTE_PUNCTUATION)
                | (1 << Character.FINAL_QUOTE_PUNCTUATION)));
        defCategory("S", ((1 << Character.MATH_SYMBOL)
                | (1 << Character.CURRENCY_SYMBOL)
                | (1 << Character.MODIFIER_SYMBOL)
                | (1 << Character.OTHER_SYMBOL)));
        defCategory("LC", ((1 << Character.UPPERCASE_LETTER)
                | (1 << Character.LOWERCASE_LETTER)
                | (1 << Character.TITLECASE_LETTER)));
        defCategory("LD", ((1 << Character.UPPERCASE_LETTER)
                | (1 << Character.LOWERCASE_LETTER)
                | (1 << Character.TITLECASE_LETTER)
                | (1 << Character.MODIFIER_LETTER)
                | (1 << Character.OTHER_LETTER)
                | (1 << Character.DECIMAL_DIGIT_NUMBER)));
        defRange预定义POSIX字符类("L1", 0x00, 0xFF); // Latin-1
        map.put("all", new CharPropertyFactory() {
            CharProperty支持补集 make() {
                charPropertyClassName=All.class.getName();
                return new All();
            }
        });

        // Posix regular expression character classes, defined in
        // http://www.unix.org/onlinepubs/009695399/basedefs/xbd_chap09.html
        defRange预定义POSIX字符类("ASCII", 0x00, 0x7F);   // ASCII
        defCtype("Alnum", ASCII.ALNUM);  // Alphanumeric characters
        defCtype("Alpha", ASCII.ALPHA);  // Alphabetic characters
        defCtype("Blank", ASCII.BLANK);  // Space and tab characters
        defCtype("Cntrl", ASCII.CNTRL);  // Control characters
        defRange预定义POSIX字符类("Digit", '0', '9');     // Numeric characters
        defCtype("Graph", ASCII.GRAPH);  // printable and visible
        defRange预定义POSIX字符类("Lower", 'a', 'z');     // Lower-case alphabetic
        defRange预定义POSIX字符类("Print", 0x20, 0x7E);   // Printable characters
        defCtype("Punct", ASCII.PUNCT);  // Punctuation characters
        defCtype("Space", ASCII.SPACE);  // Space characters
        defRange预定义POSIX字符类("Upper", 'A', 'Z');     // Upper-case alphabetic
        defCtype("XDigit", ASCII.XDIGIT); // hexadecimal digits

        // Java character properties, defined by methods in Character.java
        defClone("javaLowerCase", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isLowerCase(ch);
            }
            public String toString正集(){return "\\p{javaLowerCase}";}
            public String toString补集(){return "\\P{javaLowerCase}";}
        });
        defClone("javaUpperCase", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isUpperCase(ch);
            }
            public String toString正集(){return "\\p{javaUpperCase}";}
            public String toString补集(){return "\\p{javaUpperCase}";}
        });
        defClone("javaAlphabetic", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isAlphabetic(ch);
            }
            public String toString正集(){return "\\p{javaAlphabetic}";}
            public String toString补集(){return "\\p{javaAlphabetic}";}
        });
        defClone("javaIdeographic", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isIdeographic(ch);
            }
            public String toString正集(){return "\\p{javaIdeographic}";}
            public String toString补集(){return "\\p{javaIdeographic}";}
        });
        defClone("javaTitleCase", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isTitleCase(ch);
            }
            public String toString正集(){return "\\p{javaTitleCase}";}
            public String toString补集(){return "\\p{javaTitleCase}";}
        });
        defClone("javaDigit", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isDigit(ch);
            }
            public String toString正集(){return "\\p{javaDigit}";}
            public String toString补集(){return "\\p{javaDigit}";}
        });
        defClone("javaDefined", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isDefined(ch);
            }
            public String toString正集(){return "\\p{javaDefined}";}
            public String toString补集(){return "\\p{javaDefined}";}
        });
        defClone("javaLetter", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isLetter(ch);
            }
            public String toString正集(){return "\\p{javaLetter}";}
            public String toString补集(){return "\\p{javaLetter}";}
        });
        defClone("javaLetterOrDigit", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isLetterOrDigit(ch);
            }
            public String toString正集(){return "\\p{javaLetterOrDigit}";}
            public String toString补集(){return "\\p{javaLetterOrDigit}";}
        });
        defClone("javaJavaIdentifierStart", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isJavaIdentifierStart(ch);
            }
            public String toString正集(){return "\\p{javaJavaIdentifierStart}";}
            public String toString补集(){return "\\p{javaJavaIdentifierStart}";}
        });
        defClone("javaJavaIdentifierPart", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isJavaIdentifierPart(ch);
            }
            public String toString正集(){return "\\p{javaJavaIdentifierPart}";}
            public String toString补集(){return "\\p{javaJavaIdentifierPart}";}
        });
        defClone("javaUnicodeIdentifierStart", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isUnicodeIdentifierStart(ch);
            }
            public String toString正集(){return "\\p{javaUnicodeIdentifierStart}";}
            public String toString补集(){return "\\p{javaUnicodeIdentifierStart}";}
        });
        defClone("javaUnicodeIdentifierPart", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isUnicodeIdentifierPart(ch);
            }
            public String toString正集(){return "\\p{javaUnicodeIdentifierPart}";}
            public String toString补集(){return "\\p{javaUnicodeIdentifierPart}";}
        });
        defClone("javaIdentifierIgnorable", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isIdentifierIgnorable(ch);
            }
            public String toString正集(){return "\\p{javaIdentifierIgnorable}";}
            public String toString补集(){return "\\p{javaIdentifierIgnorable}";}
        });
        defClone("javaSpaceChar", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isSpaceChar(ch);
            }
            public String toString正集(){return "\\p{javaSpaceChar}";}
            public String toString补集(){return "\\p{javaSpaceChar}";}
        });
        defClone("javaWhitespace", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isWhitespace(ch);
            }
            public String toString正集(){return "\\p{javaWhitespace}";}
            public String toString补集(){return "\\p{javaWhitespace}";}
        });
        defClone("javaISOControl", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isISOControl(ch);
            }
            public String toString正集(){return "\\p{javaISOControl}";}
            public String toString补集(){return "\\p{javaISOControl}";}
        });
        defClone("javaMirrored", new CloneableProperty() {
            public boolean isSatisfiedBy正集(int ch) {
                return Character.isMirrored(ch);
            }
            public String toString正集(){return "\\p{javaMirrored}";}
            public String toString补集(){return "\\p{javaMirrored}";}
        });
    }
}
